<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="逯灿灿">
    <title>动漫人物展示</title>
      <style>
        *{
            box-sizing: border-box;
        }
        body{
            margin: 0;
            padding: 0;
        }
        h1{
            margin-top: 50px;
            margin-left: 44%;
        }
        .whole{
            width: 1010px;
            height: 410px; 
            margin: 100px auto; 
            position: relative;
        }
        .whole-frame{
            width: 1010px;
            height: 410px;
            margin: 0;
            padding: 0;
            border: 1px solid black;
            display: flex;
            flex-wrap: wrap;
           
        }
        .whole-frame li{
            list-style: none;
            width: 195px;
            height: 195px;
            margin: 3px; 
            background-color: lightgreen; 
            border: 1px solid black;
        }
        .whole-frame li p{
            text-align: center;
            font-size: 30px;
        }
        .whole-img {
            width: 200px;
            height: 200px;
            top: 0px;
            left: 0;
              display: none;  
            position: absolute;
            /* background-image: url('./img/1.jpg'); */
            border: 1px solid red;
        }
        .whole-img img{
            width: 198px;
            height: 198px;
        }

    </style>
</head>

<body>
    <h1>海贼王人物展示</h1>
    <div class="whole">
        <ul class="whole-frame">
            <li><p><strong>路飞</strong></p></li>
            <li><p><strong>索隆</strong></p></li>
            <li><p><strong>娜美</strong></p></li>
            <li><p><strong>乌索普</strong></p></li>
            <li><p><strong>山治</strong></p></li>
            <li><p><strong>罗宾</strong></p></li>
            <li><p><strong>弗兰奇</strong></p></li>
            <li><p><strong>乔巴</strong></p></li>
            <li><p><strong>布鲁克</strong></p></li>
            <li><p><strong>甚平</strong></p></li>
        </ul>
        <div class="whole-img">  
            <img src="./img/1.jpg" alt="">  
        </div> 
    </div>
</body>

</html>
<script>
    var framelist = document.querySelector('.whole-frame').querySelectorAll('li');
    var wholeimg = document.querySelector('.whole-img');
    var wholeimgs = document.querySelector('.whole-img').querySelector('img');
    var imgsrc=['./img/1.jpg','./img/2.jpg','./img/3.jpg','./img/4.jpg','./img/5.png',
    './img/6.jpg','./img/7.jpg','./img/8.jpg','./img/9.jpg','./img/10.jpg']
    var index = 0;
    for(var i = 0;i<framelist.length;i++){
        framelist[i].index = i;
            framelist[i].onmouseover = function(){ 
                var a = this.index*1;
                console.log(typeof(this.index));
                // console.log(typeof(a)); 
                if(this.index<=4) {
                    wholeimg.style.left=a*202+'px';
                    wholeimg.style.display = 'block';
                    wholeimg.onmouseover = function(){
                        wholeimgs.src =imgsrc[a];
                        wholeimg.style.left=a*202+'px';
                        wholeimg.style.display = 'block';
                    }
                }else{
                    wholeimg.style.left=(a-5)*202+'px';
                    wholeimg.style.top = 208+'px';
                    wholeimg.style.display = 'block';
                    wholeimg.onmouseover = function(){ 
                        wholeimgs.src =imgsrc[a]; 
                        wholeimg.style.left=(a-5)*202+'px';
                        wholeimg.style.top = 208+'px';
                        wholeimg.style.display = 'block';
                    }
                    wholeimg.onmouseout = function(){
                        wholeimg.style.left='';
                        wholeimg.style.top='';
                        wholeimg.style.display = 'none';
                    }
                } 
            }

    }
</script>